﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Spire.Pdf;
using Spire.Pdf.Annotations;
using Spire.Pdf.Annotations.Appearance;
using Spire.Pdf.Graphics;

namespace SgAotoArchiveSp
{
    public partial class FormPDF : Form
    {
        public FormPDF()
        {
            InitializeComponent();
        }

        private void btn_uploadPDF_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Multiselect = false;//该值确定是否可以选择多个文件
            dialog.Title = "请选择文件夹";
            dialog.Filter = "所有文件(*.*)|*.pdf*";
            string file = "";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                file = dialog.FileName;
            }
            PdfDocument doc = new PdfDocument();
           doc.LoadFromFile(file);
           PdfPageBase page = doc.Pages[0];
           PdfRubberStampAnnotation loStamp = new PdfRubberStampAnnotation(new RectangleF(new PointF(-5, -5), new SizeF(60, 60)));
           PdfAppearance loApprearance = new PdfAppearance(loStamp);
           PdfImage image = PdfImage.FromFile(@"C:\Users\94014\Dev\Gitee\南京项目\SgAotoArchiveSp\bin\Debug\解压文件\1.jpg");
           PdfTemplate template = new PdfTemplate(160, 160);
           template.Graphics.DrawImage(image, 0, 0);
           loApprearance.Normal = template;
           loStamp.Appearance = loApprearance;
           page.AnnotationsWidget.Add(loStamp);
           string output = Program._jyfilePath+"\\ImageStamp.pdf";
           doc.SaveToFile(output);
           MessageBox.Show("导入PDF成功,请点击确定按钮结束当前审批！");
        }
    }
}
